package com.wlzg.collectiontool.net

import android.util.Log
import com.blankj.utilcode.util.ToastUtils
import com.wlzg.collectiontool.model.bean.BaseDto
import com.wlzg.collectiontool.model.bean.GeneralDto
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

abstract class CommonObserver <T:BaseDto> : Observer<T> {
    override fun onNext(response: T) {

        if (response.code == 0||response.code ==200) {
            onSuccess(response)
        } else if (response.code == 2 || response.code == 3) {
            ToastUtils.showShort("登录超时，请重新登录")
            loginTimeOut()
        } else {
            ToastUtils.showShort(response.message)
        }
    }

    override fun onError(e: Throwable) {
        ToastUtils.showShort("网络异常,请稍后再试")
    }

    override fun onComplete() {

    }

    override fun onSubscribe(d: Disposable) {

    }

    abstract fun onSuccess(t: T)
    abstract fun loginTimeOut()
}